//
//  YYFindMusicDetailTableViewCell.swift
//  STMusic
//
//  Created by stoneobs on 2017/6/14.
//  Copyright © 2017年 stoneobs. All rights reserved.
//  详情中的播放cell

import UIKit

class YYFindMusicDetailTableViewCell: UITableViewCell {

    static var cellHeight:CGFloat = 90;
    
    var indexLable:STLabel?
    
    var titleLable:STLabel?
    
    var desLable:STLabel?
    
    var playView:YYMusicAnimationView?
    
    var model:YYTrack = YYTrack(){
        
        didSet{
            
            self.indexLable?.text = model.indexString;
            
            self.titleLable?.text = model.songname;
            
            self.desLable?.text = model.songer;

            if model.playType == .nomal {
                
                self.indexLable?.isHidden = false;
                self.titleLable?.textColor = SecendTextColor;
                self.desLable?.textColor = ThirdTextColor;
                self.playView?.isHidden = true;
            }
            if model.playType == .isPlaying {
                
                self.indexLable?.isHidden = true;
                self.titleLable?.textColor = FlatBlue();
                self.desLable?.textColor = FlatBlue();
                
                self.playView?.removeFromSuperview();
                self.playView = YYMusicAnimationView.init(frame: .init(x: 0, y: 0, width: 40, height: 30), style: .YYMusicAnimationViewStyleMiddleBottom);
                self.playView?.itemColor = FlatBlue();
                self.playView?.center = (self.indexLable?.center)!;
                self.playView?.isHidden = false;
                self.playView?.startAnimation();
                self.addSubview(self.playView!);
            }
            if model.playType == .pause {
                
                self.indexLable?.isHidden = true;
                self.titleLable?.textColor = FlatBlue();
                self.desLable?.textColor = FlatBlue();
                
                self.playView?.removeFromSuperview();
                self.playView = YYMusicAnimationView.init(frame: .init(x: 0, y: 0, width: 40, height: 30), style: .YYMusicAnimationViewStyleMiddleBottom);
                self.playView?.itemColor = FlatBlue();
                self.playView?.center = (self.indexLable?.center)!;
                self.playView?.isHidden = false;
                self.addSubview(self.playView!);
            }
            
            
            
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier);
        self.initSubview();
        self.backgroundColor = UIColor.white;
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubview() {
        self.indexLable = STLabel.init(frame: .init(x: 60, y: 0, width: 25, height: 13),
                                       text: "1",
                                       textColor: ThirdTextColor,
                                       font: 13,
                                       isSizetoFit: false,
                                       textAlignment: .left);
        self.indexLable?.centerY = CGFloat(YYFindMusicDetailTableViewCell.cellHeight/2);
        self.addSubview(self.indexLable!);
        
        self.titleLable = STLabel.init(frame: .init(x: 15 + (self.indexLable?.right)!, y: 5, width: SCREEN_WIDTH - 50 - 20, height: 13),
                                       text: "房东的猫：把美好事物走完",
                                       textColor: SecendTextColor,
                                       font: 15,
                                       isSizetoFit: false,
                                       textAlignment: .left);
        self.titleLable?.bottom = CGFloat(YYFindMusicDetailTableViewCell.cellHeight/2) - 5;
        self.addSubview(self.titleLable!);
        
        self.desLable = STLabel.init(frame: .init(x: 15 + (self.indexLable?.right)!, y: (self.titleLable?.bottom)! + 10, width: SCREEN_WIDTH - 50 - 20, height: 13),
                                     text: "房东的猫：把美好事物走完",
                                     textColor: ThirdTextColor,
                                     font: 13,
                                     isSizetoFit: false,
                                     textAlignment: .left);
        self.desLable?.lineBreakMode = .byClipping;
        self.desLable?.top = CGFloat(YYFindMusicDetailTableViewCell.cellHeight/2) + 5;
        self.addSubview(self.desLable!);
        
        

    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }



}
